package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.AttrKey;
import com.atguigu.lease.model.entity.AttrValue;
import com.atguigu.lease.web.admin.service.AttrKeyService;
import com.atguigu.lease.web.admin.service.AttrValueService;
import com.atguigu.lease.web.admin.vo.attr.AttrKeyVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 19:56$
 * description: 房间基本属性管理
 */
@Tag(name = "房间属性管理")
@RestController
@RequestMapping("/admin/attr")
public class AttrController {
    @Autowired
    private AttrKeyService attrKeyService;
    @Autowired
    private AttrValueService attrValueService;
    /**
     * 新增或更新属性值
     */
    @PostMapping("/value/saveOrUpdate")
    @Operation(summary = "新增或更新属性值")
    public Result valueSaveOrUpdate(
            @RequestBody AttrValue attrValue) {
        attrValueService.saveOrUpdate(attrValue);
        return Result.ok();
    }
    /**
     * 新增或更新属性名
     * */
    @PostMapping("key/saveOrUpdate")
    @Operation(summary = "新增或更新属性名")
    public Result keySaveOrUpdate(@RequestBody AttrKey attrKey){
        attrKeyService.saveOrUpdate(attrKey);
        return Result.ok();
    }
    /**
     * 查询全部属性名和属性值列表
     * */
    @GetMapping("list")
    @Operation(summary = "查询全部属性名和属性值列表")
    public Result<List<AttrKeyVo>> listAttrKeyAndValue(){
        List<AttrKeyVo> list = attrKeyService.listAttrKeyAndValue();
        return Result.ok(list);
    }

    /**
     * 根据id删除属性值
     * */
    @DeleteMapping("/value/deleteById")
    @Operation(summary = "根据id删除属性值")
    public Result deleteValueById(@RequestParam Long id){
        attrValueService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id删除属性名称
     * */
    @DeleteMapping("key/deleteById")
    @Operation(summary = "根据id删除属性名称")
    public Result deleteKeyById(@RequestParam long id){
        attrKeyService.removeById(id);
        return Result.ok();
    }
}
